const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

//处理事项列表
const dealItemList = list =>{
  if(list.length >1){
    //排序
    list.sort((obj1, obj2) => {
      if (obj1.level <= obj2.level) {
        return -1
      } else {
        return 1;
      }
    });
    //重置id
    list.map((obj, index) => {
      obj.id = index;
    });
  }
  return list;
}

module.exports = {
  formatTime: formatTime,
  dealItemList: dealItemList
}
